package com.servlet;

import com.dao.GoodsDAO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteGoods")
public class DeleteGoodsServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));
        GoodsDAO goodsDAO = new GoodsDAO();
        boolean success = goodsDAO.deleteGoods(id);

        if (success) {
            response.sendRedirect("listGoods");
        } else {
            response.sendRedirect("error.jsp");
        }
    }
}
